package com.example.shop_2211.order

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.base.entity.*
import com.example.base.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class OrderViewModel:BaseViewModel() {
    val getSuccess = MutableLiveData<GetPreOrderEntityResult>()
    val getFail = MutableLiveData<String>()
    fun getPreOrder(preOrderNo:String){
        viewModelScope.launch {
            try {
                getSuccess.value = apiService.getPreOrder(preOrderNo)
            }catch (e:Exception){
                getFail.value = e.message
            }
        }
    }
    val createSuccess = MutableLiveData<CreateOrderEntityResult>()
    val createFail = MutableLiveData<String>()
    fun createOrder(body:CreateOrderEntityParam){
        viewModelScope.launch {
            try {
                createSuccess.value = apiService.createOrder(body)
            }catch (e:Exception){
                createFail.value = e.message
            }
        }
    }
    val orderSuccess = MutableLiveData<OrderEntityResult>()
    val orderFail = MutableLiveData<String>()
    fun order(type:String,limit:Int,page:Int){
        viewModelScope.launch {
            try {
                orderSuccess.value = apiService.order(type,limit, page)
            }catch (e:Exception){
                orderFail.value = e.message
            }
        }
    }
}